]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st-texture-cache: Use StContentImage to create actor contents
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Wed, 27 Feb 2019 02:18:39 +0000 (03:18 +0100)
committerJonas Ådahl <jadahl@gmail.com>
Fri, 1 Mar 2019 17:12:52 +0000 (17:12 +0000)
This will allow to use resource-scale aware content that will use a preferred
size that takes in account the icon scaling and the resource scaling.

If no size is passed we should just divide the actual resource size by the
resource scale, as we assume that it's loaded with such scaling applied.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/5
https://bugzilla.gnome.org/show_bug.cgi?id=765011

src/st/st-texture-cache.c

index 0075845f892595c5e9ca9f1bce5e024898b43057..40213077063017c09f959d94161d747cd76fb411 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include "st-image-content.h"
 #include "st-texture-cache.h"
 #include "st-private.h"
 #include "st-settings.h"
@@ -486,12 +487,26 @@ load_pixbuf_async_finish (StTextureCache *cache, GAsyncResult *result, GError **
 }
 
 static ClutterContent *
-pixbuf_to_clutter_image (GdkPixbuf *pixbuf)
+pixbuf_to_st_content_image (GdkPixbuf *pixbuf,
+                            int        width,
+                            int        height,
+                            int        paint_scale,
+                            float      resource_scale)
 {
   ClutterContent *image;
   g_autoptr(GError) error = NULL;
 
-  image = clutter_image_new ();
+  if (width < 0)
+    width = ceilf (gdk_pixbuf_get_width (pixbuf) / resource_scale);
+  else
+    width *= paint_scale;
+
+  if (height < 0)
+    height = ceilf (gdk_pixbuf_get_width (pixbuf) / resource_scale);
+  else
+    height *= paint_scale;
+
+  image = st_image_content_new_with_preferred_size (width, height);
   clutter_image_set_data (CLUTTER_IMAGE (image),
                           gdk_pixbuf_get_pixels (pixbuf),
                           gdk_pixbuf_get_has_alpha (pixbuf) ?
@@ -553,7 +568,10 @@ finish_texture_load (AsyncTextureLoadData *data,
       if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
                                          &orig_key, &value))
         {
-          image = pixbuf_to_clutter_image (pixbuf);
+          image = pixbuf_to_st_content_image (pixbuf,
+                                              data->width, data->height,
+                                              data->paint_scale,
+                                              data->resource_scale);
           if (!image)
             goto out;
 
@@ -567,7 +585,10 @@ finish_texture_load (AsyncTextureLoadData *data,
     }
   else
     {
-      image = pixbuf_to_clutter_image (pixbuf);
+      image = pixbuf_to_st_content_image (pixbuf,
+                                          data->width, data->height,
+                                          data->paint_scale,
+                                          data->resource_scale);
       if (!image)
         goto out;
     }
@@ -994,7 +1015,7 @@ load_from_pixbuf (GdkPixbuf *pixbuf)
   int width = gdk_pixbuf_get_width (pixbuf);
   int height = gdk_pixbuf_get_height (pixbuf);
 
-  image = pixbuf_to_clutter_image (pixbuf);
+  image = pixbuf_to_st_content_image (pixbuf, width, height, 1, 1.0f);
 
   actor = clutter_actor_new ();
   clutter_actor_set_size (actor, width, height);
@@ -1326,7 +1347,9 @@ st_texture_cache_load_file_sync_to_cogl_texture (StTextureCache *cache,
       if (!pixbuf)
         goto out;
 
-      image = pixbuf_to_clutter_image (pixbuf);
+      image = pixbuf_to_st_content_image (pixbuf,
+                                          available_height, available_width,
+                                          paint_scale, resource_scale);
       g_object_unref (pixbuf);
 
       if (!image)